<?php

class GalleryController extends Controller{
	
	public $models = array("Gallery");
	
	public function __construct() {
		parent::__construct();
	}
	
	public function index(){
		
		$this->assign("title",$this->template_parser->get_config_vars("gallery"));
		
		$galleries = $this->Gallery->getAll();
		$this->translate($galleries, "gallery");
		
		$this->assign("galleries", $galleries);
		
		$this->display("gallery/index.html");
	}
	
	public function show($id) {
		$this->assign("title",$this->template_parser->get_config_vars("gallery"));
		
		$gallery = $this->Gallery->getAll($id);
		$this->translateRow($gallery, "gallery");
		$this->assign("gallery", $gallery);
		
		$this->display("gallery/show.html");
	}
	
	public function video($id) {
		$video = $this->Gallery->getItem($id);
		if($video && $video["type"]=="video") {
			$path = $_SERVER['DOCUMENT_ROOT']."/userfiles/gallery/{$video["gallery_id"]}/".$video["src"];
			
			switch (strtolower(substr($path,strrpos($path,".")+1))) {
				case "mp4":
					$content_type = "video/x-mp4";
					break;
				default:
					$content_type = "video/x-flv";
					break;
			}
			header("Content-Type: $content_type");
			header("Content-Disposition: inline; filename=video");
			echo file_get_contents($path);
		}
	}
}

?>